package com.zhentao.controller;

import com.zhentao.pojo.MenuBusiness;
import com.zhentao.pojo.MenuUser;
import com.zhentao.service.MenuUserService;
import com.zhentao.service.impl.MenuBusinessServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("menuUser")
public class MenuUserController {
    @Autowired
    private MenuUserService menuService;

    // 添加菜单
    @PostMapping
    public boolean addMenu(@RequestBody MenuUser menu) {
        return menuService.save(menu);
    }

    // 修改菜单
    @PutMapping
    public boolean updateMenu(@RequestBody MenuUser menu) {
        return menuService.updateById(menu);
    }

    // 删除菜单
    @DeleteMapping("/{id}")
    public boolean deleteMenu(@PathVariable Integer id) {
        return menuService.removeById(id);
    }

    // 查询所有菜单(树形结构)
    @GetMapping("/tree")
    public List<MenuUser> getMenuTree() {
        return menuService.getMenuTree();
    }

    // 根据角色获取菜单(动态菜单)
    @GetMapping("/role/{roleId}")
    public List<MenuUser> getMenuByRole(@PathVariable Integer roleId) {
        return menuService.getMenuByRole(roleId);
    }
}
